package com.situ.day7.cal;

import org.junit.Test;

public class CalDemo {


    @Test
    public void test454() {
        //AbstractCal cal = new Add(3, 5);
        AbstractCal cal = new Sub(3, 5);
        int result = cal.getResult();
        System.out.println(result);
    }

    @Test
    public void test34() {
        AbstractCal cal = CalFactory.createCal1(1);
        cal.setNum1(3);
        cal.setNum2(5);
        int result = cal.getResult();
        System.out.println(result);
    }

    @Test
    public void test324() {
        AbstractCal cal = CalFactory.createCal();
        cal.setNum1(3);
        cal.setNum2(5);
        int result = cal.getResult();
        System.out.println(result);
    }

    public static void main(String[] args) {
        Add add = new Add(3, 5);
        int result1 = add.getResult();
        System.out.println(result1);

        Sub sub = new Sub();
        sub.setNum1(3);
        sub.setNum2(5);
        int result2 = sub.getResult();
        System.out.println(result2);
    }

    @Test
    public void test44() {
        //声明成子类类型，new子类对象
        Add add = new Add(3, 2);
        //如果子类重写了getResult方法，那么调用的就是重写后的方法
        //如果子类没有重写，调用的就是从父类继承
        int result1 = add.getResult();
        System.out.println(result1);

        //声明成父类类型，new子类对象
        AbstractCal cal = new Add(3, 2);
        //Person person = new Student();
        //person = new Teacher();
        //如果子类重写了getResult方法，那么调用的就是重写后的方法
        //如果子类没有重写，调用的就是从父类继承
        int result2 = cal.getResult();
        System.out.println(result2);

        cal = new Sub(3, 2);
        int result3 = cal.getResult();
        System.out.println(result3);
    }

    @Test
    public void test66() {
        AbstractCal cal = new Div(3, 2);
        int result = cal.getResult();
        System.out.println(result);

        //'Cal' is abstract; cannot be instantiate
        //Cal cal2 = new Cal();
    }

    public void jiSuan(AbstractCal cal) {
        cal.getResult();
    }

    public void jiSuan(Add add) {
        add.getResult();
    }

    public void jiSuan(Sub sub) {
        sub.getResult();
    }


}
